<?php
 $yhendus=new mysqli("localhost", "if13", "ifikad", "if13_paulamarie");
 if(isSet($_REQUEST["peitmise_id"])){
 $kask=$yhendus->prepare("UPDATE ansamblid1 SET avalik=0 WHERE punktid=0");
 //$kask->bind_param("i", $_REQUEST["peitmise_id"]);
 $kask->execute();
 }
 if(isSet($_REQUEST["avamise_id"])){
 $kask=$yhendus->prepare("UPDATE ansamblid1 SET avalik=1 WHERE punktid=0");
 echo $yhendus->error;
 //$kask->bind_param("i", $_REQUEST["avamise_id"]);
 $kask->execute();
 }
?>
<!doctype html>
<html>
 <head>
 <title>Ansamblid</title>
 </head>
 <body>
 <h1>Ansamblid</h1>
 <h3>Saab avada ja peita neid ansambleid, kellel pole veel ühtegi punkti:</h3>

 <table>
 <?php
 $kask=$yhendus->prepare("SELECT id, ansamblinimi, avalik FROM ansamblid1 WHERE punktid=0");
 $kask->bind_result($id, $ansamblinimi, $avalik);
 $kask->execute(); 
 while($kask->fetch()){
   $ansamblinimi=htmlspecialchars($ansamblinimi);
	$avamistekst="Ava";
	$avamisparam="avamise_id";
	$avamisseisund="Peidetud";
if($avalik==1){
 $avamistekst="Peida";
 $avamisparam="peitmise_id"; 
 $avamisseisund="Avatud";
}
 echo "<tr>
 <td>$ansamblinimi</td>
 <td>$avamisseisund</td>
</tr>";
 }
echo "<a href='?$avamisparam=$id'>$avamistekst</a>"

 ?>
</table>
 </body>
</html>
<?php
 $yhendus->close();
?>